package com.anyou.mall.order.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.anyou.common.annotation.ShopScope;
import com.anyou.mall.goo.goods.domain.LiGoodsSku;
import com.anyou.mall.goo.goodsSku.domain.GooGoodsSku;
import com.anyou.mall.goo.specs.domain.SpeSpecs;
import com.anyou.mall.goo.specs.service.ISpeSpecsService;
import com.anyou.mall.order.param.OrderDeliveryParam;
import com.anyou.mall.order.vo.SpecsVo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.anyou.mall.order.domain.OrdOrder;
import com.anyou.mall.order.service.IOrdOrderService;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.common.core.page.TableDataInfo;

/**
 * 订单Controller
 *
 * @author ruoyi
 * @date 2022-03-21
 */
@Api(tags = "普通订单")
@RestController
@RequestMapping("/order/ord")
public class OrdOrderController extends BaseController
{
    @Autowired
    private IOrdOrderService ordOrderService;

    /**
     * 查询订单列表
     */
    @ApiOperation("查询订单列表")
    @PreAuthorize("@ss.hasPermi('order:ord:list')")
    @GetMapping("/list")
    @ShopScope(baseTableAlias="a")
    public TableDataInfo<List<OrdOrder>> list(OrdOrder ordOrder)
    {
        startPage();
        List<OrdOrder> list = ordOrderService.selectOrdOrderList(ordOrder);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
    @ApiOperation("导出订单列表")
    @PreAuthorize("@ss.hasPermi('order:ord:export')")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ShopScope(baseTableAlias="a")
    public void export( OrdOrder ordOrder,HttpServletResponse response)
    {
        List<OrdOrder> list = ordOrderService.selectOrdOrderList(ordOrder);
        ExcelUtil<OrdOrder> util = new ExcelUtil<OrdOrder>(OrdOrder.class);
        util.exportExcel(response, list, "订单数据");
    }

    /**
     * 普通订单详情
     */
    @ApiOperation("普通订单详情")
    @PreAuthorize("@ss.hasPermi('order:ord:query')")
    @GetMapping(value = "/{orderId}")
    public ApiResult<OrdOrder> getInfo(@PathVariable("orderId") Long orderId)
    {
        return ApiResult.success(ordOrderService.selectOrdOrderByOrderId(orderId));
    }




    /**
     * 新增订单
     */
    @ApiOperation("新增订单")
    @PreAuthorize("@ss.hasPermi('order:ord:add')")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@RequestBody OrdOrder ordOrder)
    {
        return ApiResult.success(ordOrderService.insertOrdOrder(ordOrder));
    }

    /**
     * 修改订单
     */
    @ApiOperation("修改订单")
    @PreAuthorize("@ss.hasPermi('order:ord:edit')")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@RequestBody OrdOrder ordOrder)
    {
        return ApiResult.success(ordOrderService.updateOrdOrder(ordOrder));
    }

    /**
     * 删除订单
     */
    @ApiOperation("删除订单")
    @PreAuthorize("@ss.hasPermi('order:ord:remove')")
    @Log(title = "订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderIds}")
    public ApiResult remove(@PathVariable Long[] orderIds)
    {
        return ApiResult.success(ordOrderService.deleteOrdOrderByOrderId(orderIds));
    }

    /**
     * 订单发货
     */
    @ApiOperation("订单发货")
    @PreAuthorize("@ss.hasPermi('order:ord:delivery')")
    @PostMapping(value = "/orderDelivery")
    @ApiImplicitParams({
            @ApiImplicitParam(name="orderId",dataType="Long",required=true,value="订单编号"),
            @ApiImplicitParam(name="logisticsId",dataType="Long",required=false,value="物流编号"),
            @ApiImplicitParam(name="logisticsName",dataType="String",required=false,value="物流名称"),
            @ApiImplicitParam(name="logisticsNo",dataType="String",required=true,value="物流单号"),
            @ApiImplicitParam(name="contactName",dataType="String",required=false,value="送货联系人姓名"),
            @ApiImplicitParam(name="contactPhone",dataType="String",required=false,value="送货联系人电话")
    })
    public ApiResult orderDelivery(@RequestParam(value = "orderId") Long orderId,
                                   @RequestParam(value = "logisticsId",required = false) Long logisticsId,
                                   @RequestParam(value = "logisticsName",required = false) String logisticsName,
                                   @RequestParam(value = "logisticsNo",required = false) String logisticsNo,
                                   @RequestParam(value = "contactName",required = false) String contactName,
                                   @RequestParam(value = "contactPhone",required = false) String contactPhone)
    {
        return ApiResult.success(ordOrderService.orderDelivery(orderId,logisticsId,logisticsName,logisticsNo,contactName,contactPhone));
    }
}
